package com.fengzhi.crawler.jsoup;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

import com.fengzhi.crawler.jsoup.thread.CrawlerImgThread;
import com.fengzhi.crawler.jsoup.thread.CrawlerLinkThread;

public class MyImgCrawler {

	public void startCrawler() {
		CountDownLatch latch = new CountDownLatch(6);
//		String url = "http://www.nipic.com/index.html";
//		String dir = "d:/crawler/nipic/";
//		String site = "http://www.nipic.com/";

		 String url = "http://www.163.com/";
		 String site = "";
		 String dir = "d:/fengzhi/crawlers/163/";
		
		CrawlerLinkThread linkThread = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread).start();
		CrawlerLinkThread linkThread2 = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread2).start();
		CrawlerLinkThread linkThread3 = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread3).start();
		CrawlerLinkThread linkThread4 = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread4).start();
		CrawlerLinkThread linkThread5 = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread5).start();
		CrawlerLinkThread linkThread6 = new CrawlerLinkThread(latch, url, site, dir);
		new Thread(linkThread6).start();
//
//		CrawlerImgThread imgThread = new CrawlerImgThread(latch, dir);
//		CrawlerImgThread imgThread2 = new CrawlerImgThread(latch, dir);
//		CrawlerImgThread imgThread3 = new CrawlerImgThread(latch, dir);
//		CrawlerImgThread imgThread4 = new CrawlerImgThread(latch, dir);

//		new Thread(imgThread).start();
//		new Thread(imgThread2).start();
//		new Thread(imgThread3).start();
//		new Thread(imgThread4).start();

		try {
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		MyImgCrawler imgCrawler = new MyImgCrawler();

		imgCrawler.startCrawler();
		System.out.println(Thread.currentThread().getName() + " : " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss SSS").format(new Date()));
	}
}
